package com.ipharma.gui;

import java.awt.event.ActionEvent;

import javax.swing.JButton;

import com.ipharma.McdError;
import com.ipharma.dto.Task;

/**
 * A Swing-based dialog class.
 * <P>
 * @author JorgE.H
 */
public class GUIQuantifierRce extends GUIQuantifier
{
  /**
   * The layout used by the main panel.
   */

  /**
   * The main panel.
   */

  /**
   * Attributes
   */
  Task task;

  /**
   * Constructs a new instance.
   * @param parent
   * @param title
   * @param modal
   */
  public GUIQuantifierRce( GUIOperation pContainer, String title, boolean modal )
  {
    super( pContainer, title, modal );
    try
    {
      jbInit();
      pack();
    }
    catch ( Exception e )
    {
      McdError.add( e );
    }
  }

  /**
   * Initializes the state of this instance.
   */
  private void jbInit() throws Exception
  {
    // sets labels
    jLabelQty.setText( txtAction );
    this.setQuantity( quantity );
  }

  /**
   * Sets selected product quantity
   * @param pQty quantity selected
   *
  public void setQuantity( String pQty )
  {
    this.jLabelConf.setText( txtConfirm + pQty
        + ( ( Integer.parseInt( pQty ) > 1 )? Texts.CFR_UNITS : Texts.CFR_UNIT ) + Texts.CFR_FORSURE_END );
  }

  /**
   * Sets product for quantity selection
   * @param pProd Product instance selected
   * @param pAll indicates if buttons must be all active or only those permited by quantity
   */
  public void setTask( final Task pTask )
  {
    int li_qty = 0;
    task = pTask;
    jLabelTitle.setText( task.getDescription() );
  }

  /**
   * Returns selected value
   * @return String selected value
   */
  public String getSelection()
  {
    return quantity;
  }

  void jButtCancel_actionPerformed( ActionEvent e )
  {
    quantity = "0";
    this.stop();
  }

  void jButtAcept_actionPerformed( ActionEvent e )
  {
    this.stop();
  }

  void jButton_actionPerformed( ActionEvent e )
  {
    int li_maxQty,      // quantity available
        li_selQty;      // quantity selected

    this.kickTimer();
    JButton l_butt = (JButton) e.getSource();
    li_selQty = Integer.parseInt( l_butt.getText() );
    quantity = "" + li_selQty;

    setQuantity( quantity );
  }
}

